package com.ztf.room.dao;


import com.ztf.room.bean.Evaluates;
import com.ztf.room.bean.Student;
import com.ztf.room.bean.Teachers;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface TeacherDao {

    @Select("select * from teachers where teacherId=#{teacherId}")
    Teachers selectTeacherById(int teacherId);

    @Select("select * from teachers where account =#{account} and password=#{password}")
    Teachers login(@Param("account") String account, @Param("password") String password);

    @Select("select * from evaluates where studentId=#{studentId}")
    List<Evaluates> getEvauatesByStu(Integer studentId);

    @Select("select * from evaluates where teacherId =#{id}")
    List<Evaluates> getEvauatesByTea(Integer id);

    @Select("select * from teachers")
    List<Teachers> getTeachers();

    @Insert("<script>insert into evaluates values\n" +
            "        <foreach collection=\"list\" separator=\",\" item=\"item\">\n" +
            "            (null,#{teacherId},#{teacherName},null,#{item.studentId},#{item.studentName})\n" +
            "        </foreach></script>")
    void insertRelease(@Param("teacherId") Integer teacherId,
                       @Param("teacherName") String teacherName,
                       @Param("list") List<Student> students);

    @Update("update evaluates set evaluateScore=#{evaluateScore} where evaluateScore is null and evaluateId=#{evaluateId}")
    int saveEvaluation(Evaluates evaluates);

}
